package com.example.xlljobdemo.itheima.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import groovy.util.logging.Slf4j;
import org.apache.tomcat.util.json.JSONParser;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.awt.print.PrinterAbortException;
import java.util.Map;

/**
 * @Description
 * @Author linlingxin
 * @Date 2024/9/1 21:18
 */
@Slf4j
@Service
public class TestJobService {

    private final Logger logger = LoggerFactory.getLogger(TestJobService.class);

    @XxlJob("sendMessage")
    public ReturnT<String> sendMessage(String nums) {
        // 这两个方法和视频里面演示的不一样了，在XxlJobHelper里面
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();

        logger.info("shardIndex：{}", shardIndex);
        logger.info("shardTotal：{}", shardTotal);
        String jobParam = XxlJobHelper.getJobParam();
        if (Integer.parseInt(jobParam) % 2 == 1) {
            logger.info("奇数");
        } else {
            logger.info("偶数");
        }

        //System.out.println(jobParam);
        ReturnT<String> stringReturnT = new ReturnT<>();
        stringReturnT.setMsg("发送消息成功！");
        stringReturnT.setContent("content");
        return stringReturnT;
    }
}
